package com.kiln.juxingqs.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.global.commlib.base.BaseLoadmoreAdapter
import client.global.commlib.base.BindingViewHoder
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GetDddRet
import com.kiln.juxingqs.databinding.LayoutDddjyitemBinding

class DddjyAdapter : BaseLoadmoreAdapter<GetDddRet.Order> {


    constructor(context: Context) : super(context) {
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.layout_dddjyitem,
                parent,
                false
            )
        )
    }

    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as LayoutDddjyitemBinding

        val bean = getItem(position)
        binding.bean = bean

        binding.event = this

        binding.name = bean.name + if (bean.t_type == 1) "(挂买)" else "(挂卖)"

        when (bean.status) {
            0 -> {
                binding.status = "挂牌中"
            }
            1 -> {
                binding.status = "已成交"
            }
            2 -> {
                binding.status = "手动撤销"
            }
            3 -> {
                binding.status = "系统撤销"
            }
        }
    }

    var sellFun: ((b: GetDddRet.Order) -> Unit)? = null
    var buyFun: ((b: GetDddRet.Order) -> Unit)? = null

    fun sell(b: GetDddRet.Order) {
        sellFun?.invoke(b)
    }

    fun buy(b: GetDddRet.Order) {
        buyFun?.invoke(b)
    }
}